/*
 * Copyright 2024 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.pajamas.spring.boot;

import org.springframework.boot.autoconfigure.sql.init.SqlDataSourceScriptDatabaseInitializer;
import org.springframework.boot.autoconfigure.sql.init.SqlInitializationProperties;
import org.springframework.boot.sql.init.DatabaseInitializationMode;

import java.util.Collections;

import javax.sql.DataSource;

/**
 * @author william
 * @since 2024/5/30
 */
public class ExampleDatabaseInitializer extends SqlDataSourceScriptDatabaseInitializer {
    public ExampleDatabaseInitializer(DataSource dataSource) {
        super(dataSource, getProperty());
    }

    private static SqlInitializationProperties getProperty() {
        SqlInitializationProperties properties = new SqlInitializationProperties();
        properties.setSchemaLocations(Collections.singletonList("classpath:sql/schema.sql"));
        properties.setDataLocations(Collections.singletonList("classpath:sql/data.sql"));
        properties.setMode(DatabaseInitializationMode.ALWAYS);
        properties.setContinueOnError(false);
        return properties;
    }
}